package com.qjz.view.menu
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	import mx.collections.ArrayCollection;

	[Bindable]
	/**
	 *
	 * @author qiujz
	 */
	public class MenuContext extends EventDispatcher
	{
		private static var context:MenuContext;
		
		private var version:String="0.9.2";

		/**
		 *
		 * @return
		 */
		public static function getInstance():MenuContext
		{
			if(context == null)
				context=new MenuContext();
			return context;
		}

		private var totallMenus:Object=new Object();

		/**
		 * 构造函数，配置功能点所属菜单的Index
		 * @param target
		 */
		public function MenuContext(target:IEventDispatcher=null)
		{
			super(target);

			//adminMenus 0
			totallMenus.fun100=0;
			totallMenus.fun101=0;
			totallMenus.fun102=0;
			totallMenus.fun103=0;
			totallMenus.fun104=0;
			totallMenus.fun105=0;
			totallMenus.fun106=0;
			totallMenus.fun107=0;
			totallMenus.fun108=0;
			totallMenus.fun109=0;
			totallMenus.fun110=0;
			totallMenus.fun111=0;
			totallMenus.fun999=0;
			
			//userMenus 1
			totallMenus.fun200=1;
			totallMenus.fun201=1;
			totallMenus.fun202=1;
			totallMenus.fun203=1;
			totallMenus.fun204=1;
			
			//userMenus 2
			totallMenus.fun300=2;
			totallMenus.fun301=2;
			totallMenus.fun302=2;
			totallMenus.fun303=2;
			totallMenus.fun304=2;
		}

		/**
		 * 根据ID获取菜单（功能点）
		 * @param id
		 * @return
		 */
		public function getMenuById(id:String):MenuVO
		{
			if (id == "")
				return null;

			var menuCatalog:int=totallMenus[id] as int;
			var menuVo:MenuVO;
			switch(menuCatalog){
				case 0:
					menuVo=getMenu(id, _adminMenus);
					break;
				case 1:
					menuVo=getMenu(id, _userMenus);
					break;
				case 2:
					menuVo=getMenu(id, _czMenus);
					break;
			}

			return menuVo;
		}

		private function getMenu(id:String, dts:ArrayCollection):MenuVO
		{
			for each (var obj:Object in dts)
			{
				if (obj.id == id)
				{
					return covertToMenu(obj);
				}
			}
			return null;
		}

		private function covertToMenu(obj:Object):MenuVO
		{
			var temp:MenuVO=new MenuVO();
			temp.id=obj.id;
			temp.label=obj.label;
			temp.img=obj.img;
			temp.url=obj.url;
			temp.icon=Class(obj.icon);
			return temp;
		}

		/**
		 * 已打开窗体集合
		 * @default
		 */
		public var openWin:Array=new Array;
		/**
		 *
		 * @default
		 */
		public var openWinContent:Object=new Object();

		/**
		 *
		 * @param key
		 * @return
		 */
		public function isWinOpened(key:String):Boolean
		{
			return openWinContent[key] != null;
		}

		/**
		 *
		 * @param key
		 */
		public function removeWin(key:String):void
		{
			openWinContent[key]=null;
		}

		private var urlRoot:String="com/qjz/modules/";
		private var imgRoot:String="assets/images/menu/";		

		/**
		 * 系统管理员菜单
		 * @return
		 */
		public function get adminMenus():ArrayCollection
		{
			return _adminMenus;
		}

		private var _adminMenus:ArrayCollection=new ArrayCollection([
			{id: "fun100", label: "信息同步", img: imgRoot + "daqy.png", url: urlRoot + "InfoSyncModule.swf?version="+version, selected: true},
			{id: "fun101", label: "全文搜索", img: imgRoot + "cardWatch_hover.png", url: urlRoot + "FullSchModule.swf?version="+version},
			{id: "fun103", label: "新生入学", img: imgRoot + "exportRecord.png", url: urlRoot + "AdminHGModule.swf?version="+version},
			{id: "fun105", label: "城区择校", img: imgRoot + "memberNumber_hover.png", url: urlRoot + "SchoolChoiceModule.swf?version="+version},
			{id: "fun112", label: "报表生成", img: imgRoot + "datj.png", url: urlRoot + "ReportsModule.swf?version="+version},
			{id: "fun107", label: "系统设置", img: imgRoot + "home_hover.png", url: urlRoot + "SysManageModule.swf?version="+version},
			{id: "fun999", label: "退　　出", img: imgRoot + "out.png", url: urlRoot + ""}
			]);
		
		/**
		 * 普通用户菜单
		 * @return
		 */
		public function get userMenus():ArrayCollection
		{
			return _userMenus;
		}
		
		private var _userMenus:ArrayCollection=new ArrayCollection([
			{id: "fun200", label: "信息同步", img: imgRoot + "daqy.png", url: urlRoot + "InfoSyncModule.swf?version="+version, selected: true},
			{id: "fun201", label: "全文搜索", img: imgRoot + "cardWatch_hover.png", url: urlRoot + "FullSchModule.swf?version="+version},
			{id: "fun202", label: "新生入学", img: imgRoot + "exportRecord.png", url: urlRoot + "HigherGraderModule.swf?version="+version},
			{id: "fun204", label: "账户设置", img: imgRoot + "memberNumber_hover.png", url: urlRoot + "AccountSetModule.swf?version="+version},
			{id: "fun999", label: "退　　出", img: imgRoot + "out.png", url: urlRoot + ""}
		]);
		
		/**
		 * 初中用户菜单
		 * @return
		 */
		public function get czMenus():ArrayCollection
		{
			return _czMenus;
		}
		
		private var _czMenus:ArrayCollection=new ArrayCollection([
			{id: "fun300", label: "信息同步", img: imgRoot + "daqy.png", url: urlRoot + "InfoSyncModule.swf?version="+version, selected: true},
			{id: "fun301", label: "全文搜索", img: imgRoot + "cardWatch_hover.png", url: urlRoot + "FullSchModule.swf?version="+version},
			{id: "fun302", label: "新生入学", img: imgRoot + "exportRecord.png", url: urlRoot + "HigherGraderModule.swf?version="+version},
			{id: "fun303", label: "自主选录", img: imgRoot + "dataDerived.png", url: urlRoot + "EnrollModule.swf?version="+version},
			{id: "fun304", label: "账户设置", img: imgRoot + "memberNumber_hover.png", url: urlRoot + "AccountSetModule.swf?version="+version},
			{id: "fun999", label: "退　　出", img: imgRoot + "out.png", url: urlRoot + ""}
		]);

	}
}

